42 Vowel Count 7 kyu


Posted by mijouhsieh on 2024-01-04

7 kyu Vowel Count

題目說明:

函式帶入字串判斷有幾個母音(a,e,i,o,u)

code
export class Kata {
  static getCount(str: string): number {
    //code
    const lowerCaseStr = str.trim().toLowerCase();
    const regex = /[aeiou]/g;
    const matches = lowerCaseStr.match(regex);

    if (matches) {
      return matches.length;
    } else {
      return 0;
    }
  }
}

#TypeScript #string.match() #RegEx







Related Posts

實作 Redux(四):共享結構的物件提高性能

實作 Redux(四):共享結構的物件提高性能

每週 Exit Tickets - week 1 (submitted)

每週 Exit Tickets - week 1 (submitted)

前端、後端差異 & 瀏覽器運作流程

前端、後端差異 & 瀏覽器運作流程


Comments